﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BUS;
using DTO;
using System.IO;
namespace CDT_CSDLNC
{
    public partial class ucChiTietSanPham : UserControl
    {
        public string maTinBan = null;
        public string hoten = null;
        public int soLuongMua;
        public int donGia;
        public string tenSanPham;
        public int phiVanChuyen;
        public int giaDeNghi;
        public int giaSanPham;

        public ucChiTietSanPham()
        {
            InitializeComponent();
        }

        private void cbMacCa_CheckedChanged(object sender, EventArgs e)
        {
            if (cbMacCa.Checked)
            {
                btnDatMua.Visible = false;
                btnGuiMacCa.Visible = true;
                txtGiaMacCa.Enabled = true;
            }
            else
            {
                btnDatMua.Visible = true;
                btnGuiMacCa.Visible = false;
                txtGiaMacCa.Text = "";
                txtGiaMacCa.Enabled = false;
            }
        }

        private void XuLyKichBan()
        {
            frmMain main = (frmMain)this.ParentForm;
            int flag = main.flag;
            switch (flag)
            {
                case 1:
                    main.kb1_buoc = 4;
                    main.KichBan1();
                    break;
                case 2:
                    main.kb2_buoc = 4;
                    main.KichBan2();
                    break;
                case 3:
                    main.kb3_buoc = 4;
                    main.KichBan3();
                    break;
                case 4:
                    main.kb4_buoc = 4;
                    main.KichBan4();
                    break;
            }
        }

        private void ucChiTietSanPham_Load(object sender, EventArgs e)
        {
            DataTable dt = TinBanBUS.HienThiChiTietTinBan(maTinBan);
            DataRow dr = dt.Rows[0];
            lbTieuDe.Text = dr["TieuDeTinBan"].ToString();
            lbTenSanPham.Text = dr["TenSanPham"].ToString();
            rtbMoTaChiTiet.Text = dr["MoTaChiTiet"].ToString();
            lbGiaBan.Text = dr["GiaBan"].ToString() + " VNĐ";
            lbHinhThucBan.Text = dr["HinhThucBan"].ToString();
            lbLoaiVanChuyen.Text = dr["LoaiVanChuyen"].ToString();
            lbPhiVanChuyen.Text = dr["PhiVanChuyen"].ToString() + " VNĐ";

            try
            {
                string fileName = dr["AnhDaiDien"].ToString();
                string parent = Directory.GetParent(Directory.GetParent(Application.StartupPath).ToString()).ToString();
                this.pBAnhHienThi.Image = Image.FromFile(parent + "\\Images\\" + fileName);
            }
            catch (Exception ex)
            {
            }
        }

        private void rtbMoTaChiTiet_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnGuiMacCa_Click(object sender, EventArgs e)
        {
            tenSanPham = lbTenSanPham.Text;
            soLuongMua = int.Parse(nudSoLuong.Value.ToString());
            string[] str = lbGiaBan.Text.Split(' ');
            donGia = int.Parse(str[0]);
            string[] str1 = lbPhiVanChuyen.Text.Split(' ');
            phiVanChuyen = int.Parse(str1[0]);
            giaDeNghi = int.Parse(txtGiaMacCa.Text);
            giaSanPham = donGia;
            XuLyKichBan();
        }

        private void btnDatMua_Click(object sender, EventArgs e)
        {
            tenSanPham = lbTenSanPham.Text;
            soLuongMua = int.Parse(nudSoLuong.Value.ToString());
            string[] str = lbGiaBan.Text.Split(' ');
            donGia = int.Parse(str[0]);
            string[] str1 = lbPhiVanChuyen.Text.Split(' ');
            phiVanChuyen = int.Parse(str1[0]);
            XuLyKichBan();
        }

        private void label15_Click(object sender, EventArgs e)
        {

        }
    }
}
